/*
 *每一个项包含了一个JLabel和一个JTextField
 */
package address;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.LineBorder;

/**
 *
 * @author Mavis
 */
public class Term extends JFrame{
     static int numphone=0;
     static int numphone2=1;
     static int numemail=0;
     static int numemail2=1;
     static int numIm=0;
     static int numIm2=1;
     JLabel label=new JLabel();
     JTextField text=new JTextField(50);
     JPanel panel=new JPanel();
     public JButton jbtAdd=null;
     public JButton jbtSub=null;
     JComboBox im=new JComboBox();
     JComboBox phone=new JComboBox();
     Font f=new Font("微软雅黑",Font.PLAIN,15);
     JTextArea text1=new JTextArea(5,50);   //备注框
     JTextField text2=new JTextField(80);   //个人主页栏
     JTextField textyear=new JTextField(4);
     JTextField textmonth=new JTextField(2);
     JTextField textday=new JTextField(2);
     JLabel year=new JLabel("年");
     JLabel month=new JLabel("月");
     JLabel day=new JLabel("日");
     
     
     public Term(int style,String s){

         panel.setLayout(null);   
         panel.setOpaque(false); 
         label.setText(s);
         label.setFont(f);
         label.setBounds(0, 0, 100, 25);  
         label.setOpaque(false); 
         text.setBounds(80, 0, 150, 25);
         text.setOpaque(false); 
         ImageIcon addIcon = new ImageIcon("img/add.jpg");
         ImageIcon subIcon = new ImageIcon("img/sub.jpg");
         jbtAdd=new JButton(addIcon);
         jbtSub =new JButton(subIcon);
         jbtAdd.setBounds(250, 0, 30, 25);
         jbtSub.setBounds(280, 0, 30, 25);
         jbtAdd.setContentAreaFilled(false);
         jbtAdd.setBorderPainted(false);
         jbtSub.setContentAreaFilled(false);
         jbtSub.setBorderPainted(false);
         
         im.addItem("QQ");
         im.addItem("MSN");
         im.addItem("FaceBook");
         im.addItem("Skype");
         im.addItem("ICQ");
         im.addItem("POPO");
         im.addItem("新浪UC");
         im.addItem("雅虎通");
         im.addItem("Jabber");
         im.addItem("其他");
         im.setBounds(0, 0, 67, 25);
         im.setFont(f);
         im.setBackground(Color.white);
         
         phone.addItem("手机");
         phone.addItem("私人手机");
         phone.addItem("工作手机");
         phone.addItem("电话");
         phone.addItem("工作电话");
         phone.addItem("传真");
         phone.addItem("其他");
         phone.setBounds(0, 0, 67, 25);
         phone.setFont(f);
         phone.setBackground(Color.white);
         
         
         text1.setBounds(80, 0, 200, 80);
         text1.setOpaque(false); 
         text1.setWrapStyleWord(true);
         text1.setBorder(new LineBorder(Color.black,1));
         
         text2.setBounds(80,0,200,25);
         text2.setOpaque(false); 
         
         //若输入的信息栏是可以有多个的，就出现加、减按钮
         if(style==0){   //普通信息栏
            panel.add(label);
            panel.add(text);}
         if(style==1){     //电子邮箱栏            
            panel.add(label);
            panel.add(text);
            panel.add(jbtAdd);
            jbtAdd.addActionListener(new emailAddListener());
            panel.add(jbtSub);
            jbtSub.addActionListener(new emailSubListener());
         }
         if(style==2){   //即时通讯工具栏、
             panel.add(im);
             panel.add(text);
             panel.add(jbtAdd);
             jbtAdd.addActionListener(new ImAddListener());
             panel.add(jbtSub);
             jbtSub.addActionListener(new ImSubListener());
         } 
         if(style==3){    //备注栏
             panel.add(label);
             panel.add(text1);
         }
         if(style==4){      //个人主页栏
             panel.add(label);
             panel.add(text2);
         }
         if (style==5){    //联系电话号码栏、
             jbtAdd.addActionListener(new phoneAddListener());
             jbtSub.addActionListener(new phoneSubListener());
             panel.add(phone);
             panel.add(text);
             panel.add(jbtAdd);
             panel.add(jbtSub);
         }
         if(style==6){
             panel.add(label);
             textyear.setBounds(80, 0, 40, 25);
             textyear.setOpaque(false); 
             year.setBounds(120, 0, 15, 25);
             textmonth.setBounds(135, 0, 30, 25);
             textmonth.setOpaque(false); 
             month.setBounds(165, 0, 15, 25);
             textday.setBounds(180, 0, 30, 25);
             textday.setOpaque(false); 
             day.setBounds(210, 0, 15, 25);
             panel.add(textyear);
             panel.add(year);
             panel.add(textmonth);
             panel.add(month);
             panel.add(textday);
             panel.add(day);
         }
     }
     public Term(){   
         
     }
     
  
     int getnumphone(){
         return numphone;
     }
     
     void setnumphone(int n){
         numphone=n;
     }
     
     void setnumemail(int n){
         numemail=n;
     }
     
     void setnumIm(int n){
         numIm=n;
     }

    private class emailSubListener implements ActionListener {

        public emailSubListener() {
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
           if(numemail2>1){
            panel.setVisible(false);
            numemail2--;
            }
        }
    }

    private  class emailAddListener implements ActionListener {

        public emailAddListener() {
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
           if(numemail2<10){
               numemail2++;
               numemail++;}
        }
    }

    private  class ImSubListener implements ActionListener {

        public ImSubListener() {
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
           if(numIm2>1){
            panel.setVisible(false);
            numIm2--;
            }
        }
    }

    private class ImAddListener implements ActionListener {

        public ImAddListener() {
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
           if(numIm2<10){
               numIm2++;
               numIm++;}
        }
    }

    private  class phoneAddListener implements ActionListener {

        public phoneAddListener() {
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
            if(numphone2<10){
               numphone2++;
               numphone++;}
        }
    }

    private  class phoneSubListener implements ActionListener {

        public phoneSubListener() {
        }
        @Override
        public void actionPerformed(ActionEvent ae) {
            if(numphone2>1){
            panel.setVisible(false);
            numphone2--;
            }
        }
    }

   

   
}
